package TMS.src;

import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);
        while (true) {
            User user = new User();
            Shop shop = new Shop();
            Order order = new Order();
            Commodity commodity = new Commodity();
            String in = input.nextLine();
            String ans = null;
            String[] all = {"quit", "register", "login", "logout", "printInfo",
                    "registerShop", "putCommodity", "listShop", "listCommodity", "searchCommodity", "buyCommodity", "removeCommodity", "cancelShop",
                    "putCommodityBatch", "cancelOrder", "finishOrder", "listOrder", "exportMerchantOrder", "openFile",
                    "favoriteCommodity", "cancelFavoriteCommodity", "listFavoriteCommodity", "uploadFavoriteCommodity", "readFavoriteCommodity", "buyFavoriteCommodity"};

            String[] cmd = in.trim().split("\\s+");

            if (cmd[0].equals(all[0])) {//quit
                System.out.println(user.Quit(cmd));
                if (user.Quit(cmd) == "----- Good Bye! -----")
                    System.exit(0);
            } else if (cmd[0].equals(all[1])) {//register
                ans = user.Register(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[2])) {//login
                ans = user.Login(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[3])) {//logout
                ans = user.Logout(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[4])) {//printInfo
                ans = user.PrintInfo(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[5])) {//registerShop
                ans = shop.RegisterShop(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[6])) {//putCommodity
                ans = commodity.PutCommodity(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[7])) {//listShop
                ans = shop.ListShop(cmd);
                if (ans != null)
                    System.out.println(ans);
            } else if (cmd[0].equals(all[8])) {//listCommodity
                ans = commodity.ListCommodity(cmd);
                if (ans != null)
                    System.out.println(ans);
            } else if (cmd[0].equals(all[9])) {//searchCommodity
                ans = commodity.SearchCommodity(cmd);
                if (ans != null)
                    System.out.println(ans);
            } else if (cmd[0].equals(all[10])) {//buyCommodity
                ans = commodity.BuyCommodity(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[11])) {//removeCommodity
                ans = commodity.RemoveCommodity(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[12])) {//cancelShop
                ans = shop.CancelShop(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[13])) {//putCommodityBatch
                ans = commodity.PutCommodityBatch(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[14])) {//cancelOrder
                ans = order.CancelOrder(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[15])) {//finishOrder
                ans = order.FinishOrder(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[16])) {//listOrder
                ans = order.listOrder(cmd);
                if (ans != null)
                    System.out.println(ans);
            } else if (cmd[0].equals(all[17])) {//exportMerchantOrder
                ans = order.ExportMerchantOrder(cmd);
                if (ans != null)
                    System.out.println(ans);
            } else if (cmd[0].equals(all[18])) {//openFile
                ans = order.OpenFile(cmd);
                if (ans != null)
                    System.out.println(ans);
            } else if (cmd[0].equals(all[19])) {//favoriteCommodity
                ans=commodity.favoriteCommodity(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[20])) {//cancelFavoriteCommodity
                ans=commodity.cancelFavoriteCommodity(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[21])) {//listFavoriteCommodity
                ans=commodity.listFavoriteCommodity(cmd);
                if(ans!=null)
                    System.out.println(ans);
            } else if (cmd[0].equals(all[22])) {//uploadFavoriteCommodity
                ans=commodity.uploadFavoriteCommodity(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[23])) {//readFavoriteCommodity
                ans=commodity.readFavoriteCommodity(cmd);
                System.out.println(ans);
            } else if (cmd[0].equals(all[24])) {//buyFavoriteCommodity
                ans=commodity.buyFavoriteCommodity(cmd);
                if(ans!=null)
                    System.out.println(ans);
            } else {
                System.out.println("Command '" + cmd[0] + "' not found");
            }
        }
    }
}
/*order.WriteFile(in+"\n"+ans+"\n\n" ,"./d/456.txt",true );
            if(in.trim().split(" ")[0].equals("quit")) {
                order.WriteFile("\n\n\n\n","./d/123.txt",true );
                System.exit(0);
            }*/
/*
Scanner input = new Scanner(System.in);
        Order order =new Order();
        while (true) {
            String in = input.nextLine();
            StringBuilder sb = new StringBuilder();
            sb.append(in).append('\n');

            order.WriteFile(in+"\n","./d/123.txt",true );
            if(in.trim().split(" ")[0].equals("quit")) {
                order.WriteFile("\n\n\n\n","./d/123.txt",true );
                System.exit(0);
            }
        }
        */